package main.com.oaer.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import main.com.oaer.dao.PurviewDao;
import main.com.oaer.dao.RolePurviewDao;
import main.com.oaer.model.Purview;
import main.com.oaer.service.PurviewService;

@Service
public class PurviewServiceImpl implements PurviewService {
    
	@Autowired
	PurviewDao purviewDao;
	
	@Autowired
	RolePurviewDao rolePurviewDao;
	
	@Override
	public void add(Purview purview) {
		purviewDao.add(purview);
	}

	@Override
	public List<Map<String, Object>> findPurviews() {		
		return purviewDao.findPurviews();
	}

	@Override
	public void delete(Purview purview) {
		purviewDao.delete(purview);
		rolePurviewDao.deleteByPurviewId(purview.getId());
		//递归删除子节点
		List<Purview> childPurviewList = purviewDao.findChildPurview(purview.getId());
		for(Purview childPurview:childPurviewList){
			delete(childPurview);
		}
	}

	@Override
	public Purview getPurview(String url) {
		return purviewDao.getPurview(url);
	}

	@Override
	public List<Purview> findChildPurview(Long id) {
		return purviewDao.findChildPurview(id);
	}

	@Override
	public List<Purview> findSiblingPurview(Long parentId, Long userId) {
		return purviewDao.findSiblingPurview(parentId, userId);
	}

	@Override
	public Purview load(Long id) {
		return purviewDao.load(id);
	}

	@Override
	public void update(Purview purview) {
		purviewDao.update(purview);
	}

   
}
